package com.tyylab.kestrel.framework.util;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * Configuration for header propagation
 * Supports extensible header propagation operations
 * 
 * @author tyylab
 */
public class HeaderPropagationConfig {
    
    // Default headers to propagate
    private static final Set<String> DEFAULT_PROPAGATION_HEADERS = new HashSet<>(Arrays.asList(
        "tenant_id",
        "request_id",
        "user_id",
        "trace_id"
    ));
    
    private static Set<String> propagationHeaders = new HashSet<>(DEFAULT_PROPAGATION_HEADERS);
    
    /**
     * Add a header to propagation list
     * @param headerName the header name
     */
    public static void addPropagationHeader(String headerName) {
        if (headerName != null && !headerName.trim().isEmpty()) {
            propagationHeaders.add(headerName.toLowerCase());
        }
    }
    
    /**
     * Add multiple headers to propagation list
     * @param headerNames the header names
     */
    public static void addPropagationHeaders(String... headerNames) {
        if (headerNames != null) {
            for (String headerName : headerNames) {
                addPropagationHeader(headerName);
            }
        }
    }
    
    /**
     * Remove a header from propagation list
     * @param headerName the header name
     */
    public static void removePropagationHeader(String headerName) {
        if (headerName != null) {
            propagationHeaders.remove(headerName.toLowerCase());
        }
    }
    
    /**
     * Check if a header should be propagated
     * @param headerName the header name
     * @return true if should be propagated
     */
    public static boolean shouldPropagate(String headerName) {
        if (headerName == null) {
            return false;
        }
        return propagationHeaders.contains(headerName.toLowerCase());
    }
    
    /**
     * Get all propagation headers
     * @return set of header names
     */
    public static Set<String> getPropagationHeaders() {
        return new HashSet<>(propagationHeaders);
    }
    
    /**
     * Reset to default propagation headers
     */
    public static void resetToDefault() {
        propagationHeaders = new HashSet<>(DEFAULT_PROPAGATION_HEADERS);
    }
    
    /**
     * Clear all propagation headers
     */
    public static void clear() {
        propagationHeaders.clear();
    }
} 